package net.techwatch.commons;

import javax.sql.DataSource;

import net.techwatch.commons.utils.DbUtils;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public abstract class DbTool {

	private Log log = LogFactory.getLog(DbTool.class);

	private static final String JDBC_PROPERTIES = "jdbc.properties";

	protected DataSource dataSource;
	protected String filename;

	public DbTool() {
		// nothing to do
	}

	public void init() throws InitializationException {
		dataSource = DbUtils.createDataSource(JDBC_PROPERTIES);
		
		if(dataSource == null) {
			log.fatal("Cannot initialize DB Tool");
			throw new InitializationException("Cannot initialize tool");
		}
		
		if (log.isDebugEnabled())
			log.info("DataSource created from properties");
	}

	/**
	 * @param filename
	 *            the filename to set
	 */
	public void setFilename(String filename) {
		this.filename = filename;
	}
	
	public String getFilename() {
		return this.filename;
	}

	public abstract boolean process();

}
